{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.metrics import classification_report  #对模型进行评估\n",
    "from sklearn import preprocessing  #对数据做标准化\n",
    "#数据是否需要标准化\n",
    "scale = False\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXMAAAEACAYAAABBDJb9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt8VOWdP/DPN0QhISTcolKRBKyKIBbkhbJW64Dgarut\n1tYL9ff6uW1WFxUvq1VA6y9YRfHSKu0WxQot3S7oqluwZSsKMqxuW0PBKMqlrEpAWiHIpZs1ckm+\nvz/OTDIJczln5lyec+bzfr3mxUzmzJxnTsj3PPN9vs9zRFVBREThVhJ0A4iIqHAM5kREEcBgTkQU\nAQzmREQRwGBORBQBDOZERBFgO5iLyGAReU1E3hORDSJyS+Ln/UTkFRHZIiIrRKTKu+YSEVE6YrfO\nXEROAHCCqjaKSAWAdQAuBfBtAJ+o6iMiMh1AP1Wd4VmLiYjoKLZ75qr6sao2Ju63ANgEYDCsgL4o\nsdkiAJe53UgiIsrOds+8y4tEagHEAZwBYIeq9kt5bq+q9nepfUREZIPjAdBEiuUFALcmeujdzwZc\nH4CIyGelTjYWkVJYgfxfVHVZ4se7ROR4Vd2VyKvvzvBaBnkiojyoquTaxmnPfCGAjao6N+VnLwH4\n+8T9awEs6/6ilAYZdauvrw+8DWFok6ntYpvYpmJol122e+Yi8kUA1wDYICJvwUqn3A3gYQD/JiLf\nAdAE4ErbeyciIlfYDuaq+l8AemR4epI7zSEionwU9QzQWCwWdBOOYmKbADPbxTbZwzbZZ2q77Mir\nNDGvHYmoX/siIooKEYHaGA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WWGLg+edEJ/PLAJ6xs30QwdyoSUYi8jUAO1R1Q9BtSSUiD4jIdgDfAvD/gm5PN98B\n8NugG2GQEwHsSHn8EQwIUKYTkVpYPeE3g21JRzrjLVjzZV5V1bVBtwmdnUxbJ5ZCq1mOIiKvAjg+\n9UeJxtwDa5LR91VVReQBWJOM6txug4M2fQ/A3bBSLKnPeS7bcVLVX6vq9wB8L5F/vRnArKDblNjm\nHgCHVXWx1+2x2yYKHxGpAPACgFu7fRMNROJb55jEWNBSERmhqrbSG14Qka8A2KWqjSISg4245How\nV9XJubcCAPwUgC9/jJnaJCJnAKgF8LaICKzUwToROVtVdwfRpjQWA/gP+BDMc7VJRP4e1te+iV63\nJcnBcQrSTgBDUh4PTvyM0hCRUliB/F9UdVnQ7Umlqn8VkdUALobNXLVHvgjgayLyZQBlAPqIyC9U\n9f9meoHf1SypVRlZJxn5QVXfVdUTVHWYqg6F9fV4jNeBPBcR+XzKw8tg5RUDlag8uhPA1xIDRqYJ\nMm++FsDnRaRGRI4FcDWAnNUHPhEEP6bQ3UIAG1V1btANAQARGZhM+YpIGaxv6puDbJOq3q2qQ1R1\nGKz/T69lC+SABz3zHEyfZKQw4z/+HBE5FdZxagIwNeD2AMCPARwL4FXrSwz+oKo3BtkgEbks0a6B\nAH4jIo2qeonf7VDVNhGZBqvipwTAAlU14QS8GEAMwIDE+Eu9qv4s4DZ9EcA1ADYkctQK4O6AK9sG\nAViUqEoqAfCcqv5HgO3JCycNERFFAC8bR0QUAQzmREQRwGBORBQBDOZERBHAYE5EFAEM5kREEcBg\nTkQUAQzmREQR8P8BZXtkNoyi3UAAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x27cf7a46fd0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "data = np.genfromtxt('LR-testSet.csv',delimiter = ',')\n",
    "x_data = data[:,:-1]\n",
    "y_data = data[:,-1]\n",
    "\n",
    "def plot():\n",
    "    x0 = []\n",
    "    y0 = []\n",
    "    x1 = []\n",
    "    y1 = []\n",
    "    \n",
    "    for i in range(len(x_data)):\n",
    "        if y_data[i] == 0:\n",
    "            x0.append(x_data[i,0])\n",
    "            y0.append(x_data[i,1])\n",
    "        else:\n",
    "            x1.append(x_data[i,0])\n",
    "            y1.append(x_data[i,1])\n",
    "    \n",
    "    #画图\n",
    "    scatter0 = plt.scatter(x0,y0,c='b',marker='o')\n",
    "    scatter1 = plt.scatter(x1,y1,c='r',marker='x')\n",
    "    #画图例\n",
    "    plt.legend(handles = [scatter0,scatter1],labels=['label0','label1'],loc ='best')\n",
    "    \n",
    "plot()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(100, 2)\n",
      "(100, 1)\n",
      "(100, 3)\n"
     ]
    }
   ],
   "source": [
    "#数据进行处理\n",
    "x_data = data[:,:-1]\n",
    "y_data = data[:,-1,np.newaxis]\n",
    "#转成矩阵\n",
    "print(np.mat(x_data).shape)\n",
    "print(np.mat(y_data).shape)\n",
    "#添加偏执\n",
    "X_data = np.concatenate((np.ones((100,1)),x_data),axis = 1)\n",
    "print(X_data.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def sigmoid(x):\n",
    "    return 1.0/(1+np.exp(-x))\n",
    "\n",
    "def cost(Xmat,Ymat,ws):\n",
    "    left  = np.multiply(Ymat,np.log(sigmoid(Xmat*ws)))\n",
    "    right = np.multiply(1-Ymat,np.log(1-sigmoid(Xmat*ws)))\n",
    "    return np.sum(left+right) / -(len(Xmat))\n",
    "\n",
    "def gradAscent(Xarr,Yarr):\n",
    "    \n",
    "    if scale == True:\n",
    "        Xarr = preprocessing.scale(Xarr)\n",
    "    Xmat = np.mat(Xarr)\n",
    "    Ymat = np.mat(Yarr)\n",
    "    \n",
    "    lr = 0.001\n",
    "    epochs  =10000\n",
    "    costList = []\n",
    "    \n",
    "    m,n = np.shape(Xmat) #行代表数据的个数，列代表权值的个数\n",
    "    ws = np.mat(np.ones((n,1))) #初始化权值\n",
    "    \n",
    "    for i in range(epochs+1):\n",
    "        h = sigmoid(Xmat*ws)\n",
    "        ws_grad = Xmat.T*(h - Ymat)/m\n",
    "        ws = ws - lr *ws_grad\n",
    "        \n",
    "        if i % 50 ==0:\n",
    "            costList.append(cost(Xmat,Ymat,ws))\n",
    "        \n",
    "    return ws,costList"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 2.05836354]\n",
      " [ 0.3510579 ]\n",
      " [-0.36341304]]\n"
     ]
    }
   ],
   "source": [
    "ws,costList = gradAscent(X_data,y_data)\n",
    "print(ws)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXMAAAEACAYAAABBDJb9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl4VOXZBvD7DWFJCAlJQKFiwi4QURIMS4g1KFqRutTW\nBa3lU6qiRbAqglIbKItUq5VaUVCo2ha11E/QWoWyhA8CksiOrFUIAQWCLBIJSybP98eZmczAJDkz\nc7aZuX/XNRczmTNznjkhz3nneZejRARERBTZ4uwOgIiIwsdkTkQUBZjMiYiiAJM5EVEUYDInIooC\nTOZERFFAdzJXSrVTSi1VSn2hlNqslBrl/nmqUmqRUmqHUmqhUirFvHCJiCgQpXecuVKqDYA2IrJB\nKZUEYC2AmwHcC+BbEXlOKTUWQKqIjDMtYiIiOo/ulrmIHBCRDe77lQC2AWgHLaG/5d7sLQC3GB0k\nERHVT3fL3O9FSrUHUATgUgDlIpLq89wREUkzKD4i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R09hZNy8F0FkplamU\nagLgTgANjj6wiIL9fQrnmgNgq4hMtzsQAFBKtfKUfJVSCdC+qW+3MyYReVpEMkSkI7T/T0vrS+SA\nCS3zBjh9kpHAGf/xpymlukI7TmUARtgcDwC8DKAJgP9oX2LwmYg8bGdASqlb3HG1AvAvpdQGERls\ndRwi4lJKjYQ24icOwGwRccIJeC6AAgDp7v6XQhH5i80xDQBwN4DN7hq1AHja5pFtbQG85R6VFAfg\nPRH5t43xhISThoiIogAvG0dEFAWYzImIogCTORFRFGAyJyKKAkzmRERRgMmciCgKMJkTEUUBJnMi\noijw/3D49fe6H+SZAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x27cf6926c18>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "if scale == False:\n",
    "    #画决策边界\n",
    "    plot()\n",
    "    x_test = [[-4],[3]]\n",
    "    y_test = (-ws[0] - x_test*ws[1])/ws[2]\n",
    "    plt.plot(x_test,y_test,'k')\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYYAAAEZCAYAAACTsIJzAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFTtJREFUeJzt3X+wZ3V93/Hna/fCsj/50SqolAVrjSYmIajIlHRyjW20\nYZpEWxEj+WHSTNpOg01Tf2DGYTuZSetk8oOqdWJUavghthQVU2rQ4nWqKKIsgQCmWhRWBDTNssCy\nLOzy7h/fc9l7Lnvv3mXv+Z5z7/f5mPnOPd/P9/z4nI8rr+/n8znnfFNVSJI0a03fFZAkDYvBIElq\nMRgkSS0GgySpxWCQJLUYDJKkFoNBOkxJ1iR5OMnJfddF6kK8j0GrXZKHgdl/6BuBvcD+puzXq+qj\nfdVNGiKDQRMlyV3Ar1bV5xZZZ21V7R9jtaRBc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f7mWUTbm79vW8Z9b01y23LtTxqSTn/BTerZ7ho9i6gr3gSkVckeg1azgz4s\nLMm3kry7+VGTLyd5flO+Ncn/SnJLks80jwknybOTXN2Ub09yVrOrqebJqH+Z5NNJ1jXrX5DRj+/c\nkuSKsZyptIwMBq1m6+cNJb1+zmc7q+pHgPcBs8+weg9wSVWdzugxBe9pyv8TMNOUn8HouUYAfw94\nT1W9BNgF/NOm/O2MfpzpdOBfdHVyUld8JIZWrSQPVdWWg5R/C3hlVX27efLtfVX1rCTfB06qqv1N\n+Xer6tlJvgc8r0Y/KDW7j63AdVX1A837twFTVfW7Sa5l9CjtTwCfqKrd3Z+ttHzsMWhS1QLLh2Pv\nnOX9HJizOwd4L6PexU1J/P+ZVhT/wWo1W+wHSd7Q/D0P+FKz/EXgjc3y+cD/bpY/C/wrgCRrmp/m\nXGz/p1TV5xn9+M4WRr/1La0YXpWk1eyYJDcz+g94AZ+uqnc2nx2f5C+AxzgQBhcAlyT5d8D3GT3+\nGODfAB9I8qvAPkY/rn4/B+lpNENQlzXhEUaPP36ok7OTOuIcgyZOM8fw0jrEr1hJk8qhJE0ivw1J\ni7DHIElqsccgSWoxGCRJLQaDJKnFYJAktRgMkqQWg0GS1PL/AVKQUUbiU1q2AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x27cf6926fd0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#画loss的值\n",
    "x = np.linspace(0,10000,201)\n",
    "plt.plot(x,costList,'r')\n",
    "plt.title('Train')\n",
    "plt.xlabel('Epochs')\n",
    "plt.ylabel('Cost')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "             precision    recall  f1-score   support\n",
      "\n",
      "        0.0       0.82      1.00      0.90        47\n",
      "        1.0       1.00      0.81      0.90        53\n",
      "\n",
      "avg / total       0.92      0.90      0.90       100\n",
      "\n"
     ]
    }
   ],
   "source": [
    "#做预测\n",
    "def predict(x_data,ws):\n",
    "     if scale == True:\n",
    "        x_data = preprocessing.scale(x_data)\n",
    "     Xmat = np.mat(x_data)\n",
    "     ws = np.mat(ws)\n",
    "     return [1 if x >= 0.5 else 0 for x in sigmoid(Xmat*ws)]\n",
    "\n",
    "predictions = predict(X_data,ws)\n",
    "\n",
    "print(classification_report(y_data,predictions))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
